package JzOffer.jz47;

/**
 * @author 张取
 * @version 1.0
 * @date 2022/1/20 下午10:10
 * JzOffer.jz47
 */

public class Solution01 {
    public TreeNode pruneTree(TreeNode root){
        if(root == null){
            return null;
        }
        root.left = pruneTree(root.left);
        root.right = pruneTree(root.right);
        if(root != null && root.val == 0 && root.left == null && root.right == null){
            root = null;
        }
        return root;
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    public TreeNode(){}

    public TreeNode(int val){
        this.val = val;
    }

    public TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
